/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package redis.manage;

/**
 *
 * @author dell
 */
import entity.structure.User;
import entity.support.KeyValue;
import java.lang.reflect.Field;
import redis.clients.jedis.Jedis;
import java.util.Map;
import java.util.HashMap;
public abstract class Redis 
{
//columns_______________________________________________________________________
protected KeyValue<Class,Integer>[] maps;
protected Jedis jedis;
protected boolean initialized=false;
//functions_____________________________________________________________________
     //getter___________________________________________________________________
public KeyValue<Class, Integer>[] getMaps() 
{
     return maps;
}
public boolean getInitialized()
{
     return this.initialized;
}
     //setter___________________________________________________________________
public void setMaps(KeyValue<Class, Integer>[] maps) 
{
     this.maps = maps;
}
     //operator_________________________________________________________________
/**
 * read an xml file in specified url,and init
 * @param url 
 */
protected abstract void init(String url);
/**
 * get the index of database accoring to the Class of the object
 * @param c
 * @return 
 */
protected abstract int getDBIndex(Class c);
/**
 * delete an element in Redis by key
 * @param key
 * @return 
 */
public long delete(String key)
{
     return jedis.del(key);
}
/**
 * delete elements in Redis by keys
 * @param key
 * @return 
 */
public long delete(String ...key)
{
     return jedis.del(key);
}
/**
 * expire an elemnt by key in Redis for seconds 
 * @param key
 * @param seconds
 * @return 
 */
public long expire(String key,int seconds)
{
     return jedis.expire(key,seconds);
}
public void destroy()
{
     jedis.close();
}
     //toString_________________________________________________________________
@Override
public String toString()
{
     String str="["+maps[0];
     for(int i=1;i<maps.length;i++) str+=","+maps[i];
     return str;
}
}
